package com.edu.project.http;

import android.util.Log;

import com.edu.project.bean.HttpResult;
import com.edu.project.bean.UserData;
import com.edu.project.bean.Weather;
import com.edu.project.utils.CryptoUtils;
import com.edu.project.utils.RxUtils;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by sheng on 2016/11/5.
 */
public class RequsetApi {

    public static void newsList(int pageIndex, int pageSize, HttpResultSubscriber<HttpResult<UserData>> subscriber) {
        try{
            String mPageIndex = CryptoUtils.AesEncrypt(String.valueOf(pageIndex));
            String mPageSize = CryptoUtils.AesEncrypt(String.valueOf(pageSize));
            RxUtils.unsubscribe();
            RxUtils.subscription = HttpClient.getmApi().getUserList(mPageIndex,mPageSize)
                    .subscribeOn(Schedulers.io())
                    .unsubscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(subscriber);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    public static void getWeathwerData(HttpResultSubscriber<Weather> subscriber) {
        RxUtils.unsubscribe();
        RxUtils.subscription = HttpClient.getmApi().getWeatherData()
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }


}
